<?php

namespace app\cxapi\controller;

use think\Db;

class Index
{
    public function login()
    {
        if (request()->isPost()) {
            $param = [
                'username' => request()->param()['account'],
                'password' => user_md5(request()->param()['password']),
            ];
            $result = Db::name('admin_user')->where($param)->find();
            if ($result) {
                $arr = [
                    'uid' => $result['id'],
                    'time' => time() 
                ];
                $data = [
                    'token' => encrypt(json_encode($arr), 'cxzxsxs', time()),
                ];
                cache("CX_".$result['id'], $data['token']);

                return resultArray(['data' => $data]);
            }
        }
        return resultArray(['error'=>'请求token失败']);
    }

   
}
